#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：hiflyworks_web_tests 
@File    ：step_screenshot.py
@Author  ：beibei
@Date    ：2025/6/20 4:23 PM 
'''
import os
from datetime import datetime


def step_screenshot(page, step_name: str):
    """
    截图并保存到指定路径，文件名包含时间戳和步骤名
    :param page: Playwright 的 page 对象
    :param step_name: 自定义步骤名称（如 login_button_clicked）
    """
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    folder = "screenshots/login"
    os.makedirs(folder, exist_ok=True)
    filename = f"{timestamp}_{step_name}.png"
    full_path = os.path.join(folder, filename)
    page.screenshot(path=full_path)
    print(f"✅ 已保存截图: {full_path}")
    return full_path



